package icu.groot.alan.hotel.util.scheduled;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import icu.groot.alan.hotel.entity.dao.OrderDo;
import icu.groot.alan.hotel.enums.OrderStatusEnum;
import icu.groot.alan.hotel.service.OrderService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Component
public class ScheduledOrder {

    @Resource
    OrderService orderService;

    @Scheduled(cron = "0 0 12 * * ?")
    public void scheduledFixed(){
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        executorService.submit(()->{
            orderService.update(new UpdateWrapper< OrderDo >().le("checkin_end_time", LocalDateTime.now()).set("order_status", OrderStatusEnum.FINISH));
        });
    }
}
